package com.sky.loveshop.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sky.loveshop.entity.OpenDoorHistory;
import com.sky.loveshop.entity.qo.OpenDoorHistoryQO;
import com.sky.loveshop.mapper.OpenDoorHistoryMapper;
import com.sky.loveshop.service.OpenDoorHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xcy
 * @version V1.0
 * @description 开门记录
 * @date 2024/11/4 22:56
 */
@Slf4j
@Service
public class OpenDoorHistoryServiceImpl implements OpenDoorHistoryService {

    @Resource
    private OpenDoorHistoryMapper openDoorHistoryMapper;

    @Override
    public PageInfo<OpenDoorHistory> listOpenDoorHistoryPages(OpenDoorHistoryQO qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        if (StringUtils.isNotEmpty(qo.getKeywords())) {
            qo.setPhone(qo.getKeywords());
        }
        List<OpenDoorHistory> list = openDoorHistoryMapper.searchAll(qo);
        if (CollectionUtil.isEmpty(list)) {
            return new PageInfo<>();
        }
        return new PageInfo<>(list);
    }

    @Override
    public OpenDoorHistory getOpenDoorHistoryById(Integer id) {
        return openDoorHistoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer addOpenDoorHistory(OpenDoorHistory openDoorHistory) {
        return openDoorHistoryMapper.insert(openDoorHistory);
    }

    @Override
    public Integer updateOpenDoorHistoryById(OpenDoorHistory openDoorHistory) {
        return openDoorHistoryMapper.updateByPrimaryKey(openDoorHistory);
    }
}
